#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5 + 10;
// ll a[N];
bool check(ll x, ll *k)
{
    ll al = x / 3ll + x / 5ll - x / (3ll * 5ll) - x / 6ll - x / 10ll + x / 30ll;
    return al < *k;
}
void solve()
{
    ll k;
    // cin >> k;
    //  vector<ll> a;
    //  ll cnt = 1;
    //  for (ll i = 1; i <= 200;i+=2)
    //  {
    //      if(i%10==5)
    //      {
    //          a.push_back(i);
    //      }
    //      else if(i%3==0)
    //      {
    //          a.push_back(i);
    //      }
    //  }
    //  sort(a.begin(),a.end());
    //  for (ll i = 0; i < a.size();i++)
    //  {
    //      printf("第%d个：", i+1);
    //      cout << a[i] << endl;
    //  }

    cin >> k;
    ll l = 1, r = 1e18;
    while (l < r)
    {
        ll mid = (l + r) / 2;
        if (check(mid, &k))
        {
            l = mid + 1;
        }
        else
        {
            r = mid;
        }
    }
    cout << l << endl;
}
int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}